package org.td.engine.entity;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import org.td.Application;

import java.util.HashMap;
import java.util.Map;

public class ParticleFactory {

    private Map<String, ParticleEffect> particles;

    public ParticleFactory() {
        particles = new HashMap<String, ParticleEffect>();
        ParticleEffect effect = new ParticleEffect();

        effect.load(Gdx.files.internal("assets/particles/star"), Application.getAssetManager().get("assets/assets.atlas", TextureAtlas.class));
        loadEffect(effect, "star");
    }

    public void loadEffect(ParticleEffect effect, String name) {
        particles.put(name, effect);
    }

    public ParticleEffect createParticle(String name) {
        ParticleEffect source = particles.get(name);
        if (source != null) {
            return new ParticleEffect(source);
        }

        return null;
    }

    public void dispose() {
        for (ParticleEffect p : particles.values()) {
            p.dispose();
        }
    }
}
